package de.java.shortys.utils.string;

import java.util.Random;

public final class StringUtils {

	private static final String[] CAHRACTERS = new String[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K",
			"L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
	private static final String[] NUMBERS = new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" };

	public static String firstToLowerCase(String target) {
		if ((target == null) || (target.length() == 0)) {
			return target;
		}
		return Character.toLowerCase(target.charAt(0)) + (target.length() > 1 ? target.substring(1) : "");
	}

	public static String firstToUpperCase(String target) {
		if ((target == null) || (target.length() == 0)) {
			return target;
		}
		return Character.toUpperCase(target.charAt(0)) + (target.length() > 1 ? target.substring(1) : "");
	}

	public static String generateRandom(int length) {
		final Random rnd = new Random();
		final StringBuffer key = new StringBuffer();
		for (int i = 0; i < length; i++) {
			String[] box = getBox();
			key.append(box[rnd.nextInt(box.length)]);
		}

		return key.toString();
	}

	private static String[] getBox() {
		Random rnd = new Random();
		int nextInt = rnd.nextInt(50);
		if (nextInt > 20) {
			return CAHRACTERS;
		}
		return NUMBERS;
	}

	public static boolean isNullOrEmpty(String s) {
		if (s == null) {
			return true;
		}

		if (s.length() == 0) {
			return true;
		}

		return false;
	}

	private StringUtils() {
		// Empty
	}
}
